package com.ruoyi.dynamic.controller.app;


import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.MultiVO;
import com.ruoyi.common.core.pojo.vo.SingleVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomUserSearchRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomWishAddOrEditRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomWishCloseRequest;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomWishGiveInfoResult;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomWishResult;
import com.ruoyi.dynamic.service.IRoomWishService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;


@Tag(name = "App-房间心愿单相关", description = "App-房间心愿单相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-wish")
public class AppRoomWishController {

    private final IRoomWishService roomWishService;

    public AppRoomWishController(IRoomWishService roomWishService) {
        this.roomWishService = roomWishService;
    }

    @Operation(summary = "列表", description = "列表")
    @GetMapping("listPage")
    public MultiVO<AppRoomWishResult> listPage(@ParameterObject @Validated AppRoomUserSearchRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        List<AppRoomWishResult> list = roomWishService.listPage(userId, request);
        return Result.multi(list);
    }

    @Operation(summary = "添加编辑心愿单", description = "添加编辑心愿单")
    @PostMapping("addOrEdit")
    public BaseVO addOrEdit(@RequestBody @Validated AppRoomWishAddOrEditRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = roomWishService.addOrEdit(request, userId);
        return Result.successOrFail(add);
    }

    @Operation(summary = "删除心愿", description = "删除心愿")
    @GetMapping("del")
    public BaseVO del(Long id) {
        roomWishService.delWish(id);
        return Result.success();
    }

    @Operation(summary = "心愿单赠送详情", description = "心愿单赠送详情")
    @GetMapping("giveInfo")
    public SingleVO<AppRoomWishGiveInfoResult> info(@Valid AppRoomWishCloseRequest request) {
        return Result.single(roomWishService.giveInfo(request, SecurityContextHolder.getUserId()));
    }

    @Operation(summary = "开启心愿单", description = "开启心愿单")
    @PostMapping("open")
    public BaseVO open(@RequestBody @Valid AppRoomWishCloseRequest request) {
        return Result.successOrFail(roomWishService.open(request, SecurityContextHolder.getUserId()));
    }

    @Operation(summary = "关闭心愿单", description = "关闭心愿单")
    @PostMapping("stop")
    public BaseVO stop(@RequestBody @Valid AppRoomWishCloseRequest request) {
        return Result.successOrFail(roomWishService.stop(request, SecurityContextHolder.getUserId()));
    }

    @Operation(summary = "换一换", description = "换一换")
    @PostMapping("exchange")
    public BaseVO exchange(@RequestBody @Valid AppRoomWishCloseRequest request) {
        return Result.successOrFail(roomWishService.exchange(request, SecurityContextHolder.getUserId()));
    }


}

